#include <iostream>
#include <string>
#include <thread>
#include <unistd.h>

#include "Log.hpp"
#include "Message.hpp"
#include "net.hpp"

using namespace LogArea;


void OnMessage(const MyRpc::BaseConnection::con_ptr& conn,MyRpc::BaseMessage::msg_ptr& msg)
{
    std::string body = msg->Serialize();
    LogArea::LOG(LogLevel::DEBUG)<<"Client get message body: "<<body;
}


int main()
{
    auto client = MyRpc::MuduoClientFactory::create("127.0.0.1",9092);
    client->SetMsgCb(OnMessage);
    client->Connect();

    auto rpc_req = MyRpc::MessageFactory::create<MyRpc::RpcRequest>();
    rpc_req->SetId("11111");
    rpc_req->SetMethod("Add");
    rpc_req->SetMtype(MyRpc::MType::REQ_RPC);

    Json::Value params;
    params["num1"] = 11;
    params["num2"] = 22;

    rpc_req->SetParams(params);
    client->Send(rpc_req);

    std::this_thread::sleep_for(std::chrono::seconds(10));
    // std::this_thread::sleep_for(std::chrono::seconds(10));
    client->DisConnect();
    return 0;
}